package mp1.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import mp1.entity.Product;
import mp1.exception.ProductAdminException;
import mp1.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Service
public class ProductService {
    @Autowired
    ProductMapper productMapper;

    public Product addPro(Product product){
        productMapper.insert(product);
        return product;
    }

    public void deleteProById(Long id) throws ProductAdminException {
        productMapper.deleteById(id);
    }


    public Product findProById(Long id){
        return productMapper.selectById(id);
    }

    public void updatePro(Product product){
        productMapper.updateById(product);
    }
    public List<Product> findProByName(String name){
        QueryWrapper<Product> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("name",name);
        return productMapper.selectList(queryWrapper);
    }
    public List<Product> findProByCategory(String cate){
        QueryWrapper<Product> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("category",cate);
        return productMapper.selectList(queryWrapper);
    }

    public List<Product> findProByQuantity(double min_quan,double max_quan){
        QueryWrapper<Product> queryWrapper=new QueryWrapper<>();
        queryWrapper.ge("quantity",min_quan).le("quantity",max_quan);
        return productMapper.selectList(queryWrapper);
    }

    public List<Product> findProByPrice(double min_pri,double max_pri){
        QueryWrapper<Product> queryWrapper=new QueryWrapper<>();
        queryWrapper.ge("price",min_pri).le("price",max_pri);
        return productMapper.selectList(queryWrapper);
    }

    public List<Product> findProBySupplier(String supplierName){
        return productMapper.findProBySupplier(supplierName);
    }








}
